﻿using System;
using System.Collections.Generic;
using System.Text;

namespace server
{  
    class AddUserDB
    {
        private string  username;

        public AddUserDB()
        {
            userdata.ReadDb();
        }

        private UserData userdata = new UserData();

        public void Adduser(string name)
        {
            this.username = name;
            UserData.User user = new UserData.User();
            user.UserName = username;
            user.UserInfo = new UserData.UserInfo();
            user.UserInfo.QQ = "";
            user.UserInfo.MSN = "";
            user.UserInfo.Email ="";
            user.UserInfo.Phone ="";
            userdata.Users.Add(user.UserName, user);
            userdata.WriteDb();
        }

        public void Updateinfo(string[] info)
        {
            string updatename, QQ, MSN, Email, Phone,psw;
            psw = info[3];
            updatename = info[1];
            QQ = info[4];
            MSN = info[5];
            Email = info[6];
            Phone = info[7];          
            foreach (KeyValuePair<string, UserData.User> user in this.userdata.Users)
            {
                if (user.Value.UserName == updatename)
                {
                    user.Value.UserPwd = psw;
                    user.Value.UserInfo.QQ = QQ;
                    user.Value.UserInfo.MSN = MSN;
                    user.Value.UserInfo.Email = Email;
                    user.Value.UserInfo.Phone = Phone;
                }
            }
            userdata.WriteDb();
        }

        public void DeleteInfo(string name)
        {

            userdata.Users.Remove(name);

            userdata.WriteDb();
        }
    }
}
